let rec get_lines i = 
  let lines = ref [] in
  try
    while true do
      let line = input_line i in
      lines := line :: !lines
    done ;
    []
  with End_of_file -> List.rev !lines

let write_lines o lines = 
  List.iter 
    (fun line -> 
      output_string o line ;
      output_char o '\n') lines

let sub_string ocaml s = 
  let flag = ref false in
  let size = String.length ocaml in
  for i = 0 to String.length s - size do
    let sub_s = String.sub s i size in
    if sub_s = ocaml then flag := true
  done ;
  !flag

let () = 
  match Sys.argv with
  | [|_; str; i|] ->
      (try
        let i = open_in i in
        let lines = get_lines i in
        List.iteri 
          (fun i line -> 
            if sub_string str line then
              Printf.printf "Line %i: %s\n" (i + 1) line
            ) lines ;
        close_in i ;
      with _ -> ())
  | _ ->
      print_string "usage: string input"